package com.powernode.model;

import com.powernode.constant.BusinessEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @description:
 * @author: mky
 * @date: 2024/7/4 14:44
 * @version: 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {
    private Integer code = 200;
    private String msg = "ok";
    private T data;

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setData(data);
        return result;
    }

    public static Result failure(Integer code, String msg){
        Result result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }

    public static Result failure(BusinessEnum businessEnum){
        Result<Object> result = new Result<>();
        result.setCode(businessEnum.getCode());
        result.setMsg(businessEnum.getMsg());
        result.setData(null);
        return result;
    }
}
